//  健康报表页面
//  HealthReportViewController.m
//  yilutongxing
//
//  Created by T&J on 2017/7/2.
//  Copyright © 2017年 YZE. All rights reserved.
//
#import "UIView+Layout.h"
#import "CommonDefine.h"
#import "DataUtils.h"
#import "TimeTools.h"
#import "UIView+Grid.h"
#import "AppDelegate.h"
#import "DataGridCell.h"
#import "HealthReportViewController.h"
#import "ZhuanXiangZhiBiaoViewController.h"
#import "RPSpecialIndicatorBean.h"
#import "TherapeuticRegimenViewController.h"
#import "SIChartViewController.h"

#define BOTTOM_OFFSET 65 //底部神秘偏移量
#define GRID_TAG_BASE 10000000 //横向表格tag基数

#define TEXT_COLOR_DARK [UIColor colorWithRed:80/255.0 green:80/255.0 blue:80/255.0 alpha:1.0]

#define BG_COLOR_LIGHT [UIColor colorWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:1.0]

#define URL_GetSpecialIndicatorData @"/api/sickpeople/report?page=0&size=10000"

@interface HealthReportViewController ()<UITableViewDelegate, UITableViewDataSource, UIScrollViewDelegate, ZhuanXiangZhiBiaoViewControllerDelegate>
@property (strong, nonatomic) IBOutlet UITableViewCell *headcell;
@property (strong, nonatomic) IBOutlet UIView *colorIndicatorBlockL;
@property (strong, nonatomic) IBOutlet UIView *databox;
@property(strong,nonatomic) NSMutableArray *allSpecialIndicatorArr;
//坐标及尺寸
@property (assign, nonatomic) CGPoint kOrigin;//表格原点
//控件
@property (strong, nonatomic) UIView *check_item_navi;//"检查项目"导航按钮
@property (strong, nonatomic) UITableView *leftColList;//列
@property (strong, nonatomic) UITableView *dataTable;//数据表
@property (strong, nonatomic) UIScrollView *dataScroller;//数据表横向滑动容器
//数据
@property (strong, nonatomic) NSNumber *lastRowCount;//数据表上一次的行数
@property (strong, nonatomic) NSNumber *lastColCount;//数据表上一次的列数
@property (strong, nonatomic) NSMutableArray *dateArr;//日期数组
@property (strong, nonatomic) NSMutableArray *headColArr;//头部数据数组,元素类型为NSDictionary,包含 title:val,ref:val 键值对
@property (strong, nonatomic) NSMutableArray *refArr;//以行为单位存储参考值
@property (strong, nonatomic) NSMutableArray *indicatorDataArr;//指标数据,二维数组,元素类型为NSDictionary。依次存储某项指标的所有 日期:值 的键值对

@property (strong, nonatomic) NSMutableArray *allIndicatorArr;
@property (strong, nonatomic) NSMutableDictionary *subIndicatorDic;
@property (strong, nonatomic) NSArray *subIndicatorChoosens;

//缓存网络请求返回的数据
@property (strong, nonatomic) NSDictionary *reqData;
@end

@implementation HealthReportViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"健康报表";
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationbarBackGroundImage"]
                                                  forBarMetrics:UIBarMetricsDefault];
    UIImage *img = [[UIImage imageNamed:@"返回"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:img
                                                                            style:UIBarButtonItemStyleDone
                                                                           target:self
                                                                           action:@selector(backAction)];
    
    UITapGestureRecognizer *tapG = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(goTabletPlan)];
    [self.headcell addGestureRecognizer:tapG];
    
    //创建UI
    debugLog(@"[SHENMI]block.y:%f,block.height:%f", _colorIndicatorBlockL.y, _colorIndicatorBlockL.height);
    _kOrigin = CGPointMake(-1, 0);
    
}

- (void)viewWillAppear:(BOOL)animated{
    __weak AppDelegate *app = (AppDelegate*)[[UIApplication sharedApplication] delegate];
    app.allowRotation = YES;
}

- (void)viewDidLayoutSubviews{
    if (self.databox.subviews.count>0) {
        [self.databox.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    }
    
    [self createDataTableContainer];
    [self createDatatable:_dataScroller];
    [self createDataHead:_dataScroller];
    [self createDateCol];
    [self createHeadOfDateCol];
    if ([DataUtils fileIfExists:CHOOSEN_PROINDEX]) {
        [self getData];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - 事件响应
- (void)backAction{
    [self rotate2Portrait];
    [self dismissViewControllerAnimated:YES completion:nil];
}
//打开检查项目选择界面
- (void)goIndicatorsList{
    ZhuanXiangZhiBiaoViewController *v = [ZhuanXiangZhiBiaoViewController new];
    v.delegate = self;
    [self.navigationController pushViewController:v animated:YES];
}

//打开用药方案界面
- (void)goTabletPlan{
    UINavigationController *navi=[[UINavigationController alloc]initWithRootViewController:[TherapeuticRegimenViewController new]];
    [self presentViewController:navi animated:YES completion:nil];
}

#pragma mark UI创建
//创建行头部
- (void)createHeadOfDateCol{
    _check_item_navi = [UIView createGrid:GridBorderLeft | GridBorderTop | GridBorderRight | GridBorderBottom
                    backgroundColor:COLOR(255, 255, 255)
                         titleColor:TEXT_COLOR_DARK
                          titleSize:14
                             origin:_kOrigin
                               size:CGSizeMake(CELL_WIDTH_BIG, CELL_HEIGHT_BIG)];
    //点击事件
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(goIndicatorsList)];
    [_check_item_navi addGestureRecognizer:tap];
    ((UILabel*)[_check_item_navi viewWithTag:INNERLABEL_TAG]).text = @"检查项目 >";
    [self.databox addSubview:_check_item_navi];
}

//创建左侧列TableView
- (void)createDateCol{
    CGFloat tyOrigin = _kOrigin.y + CELL_HEIGHT_BIG - 1;
    _leftColList = [[UITableView alloc]initWithFrame:CGRectMake(_kOrigin.x, tyOrigin, CELL_WIDTH_BIG, _databox.frame.size.height - tyOrigin)
                                            style:UITableViewStylePlain];
    _leftColList.delegate = self;
    _leftColList.dataSource = self;
    _leftColList.separatorStyle = UITableViewCellSeparatorStyleNone;
    _leftColList.showsVerticalScrollIndicator = NO;
    [self.databox addSubview:_leftColList];
}

//创建数据表容器
- (void)createDataTableContainer{
    _dataScroller = [[UIScrollView alloc] initWithFrame:CGRectMake(_kOrigin.x + CELL_WIDTH_BIG - 1,
                                                                   _kOrigin.y,
                                                                   SCREEN_WIDTH - CELL_WIDTH_BIG,
                                                                   _databox.frame.size.height - _kOrigin.y)];
    //_dataScroller.delegate = self;
    _dataScroller.showsHorizontalScrollIndicator = NO;
    CGSize size = _dataScroller.contentSize;
    size.width = self.dateArr.count*CELL_WIDTH_SMALL;
    _dataScroller.contentSize = size;
    [self.databox addSubview:_dataScroller];
}

//创建数据表head
- (void)createDataHead:(UIScrollView*)container{
    for (int i=0; i<self.dateArr.count; i++) {
        UIView *gridH = [UIView createGrid:GridBorderLeft | GridBorderTop | GridBorderRight | GridBorderBottom
                         backgroundColor:BG_COLOR_LIGHT
                              titleColor:TEXT_COLOR_DARK
                               titleSize:12
                                  origin:CGPointMake(i*(CELL_WIDTH_SMALL - 1), 0)
                                    size:CGSizeMake(CELL_WIDTH_SMALL, CELL_HEIGHT_BIG)];
        gridH.tag = GRID_TAG_BASE + i + 1;
        UILabel *l = [gridH viewWithTag:INNERLABEL_TAG];
        NSString *str = self.dateArr[i];
        l.text = str;
        [container addSubview:gridH];
    }
}

//创建数据表正文
- (void)createDatatable:(UIScrollView*)container{
    CGPoint tOriginPoint = CGPointMake(0, CELL_HEIGHT_BIG - 1);
    _dataTable = [[UITableView alloc]initWithFrame:CGRectMake(tOriginPoint.x, tOriginPoint.y, container.contentSize.width + 1, container.height - tOriginPoint.y) style:UITableViewStylePlain];
    _dataTable.separatorStyle = UITableViewCellSeparatorStyleNone;
    _dataTable.showsVerticalScrollIndicator = NO;
    _dataTable.allowsSelection = NO;
    _dataTable.delegate = self;
    _dataTable.dataSource = self;
    [container addSubview:_dataTable];
}

//更新数据表格
- (void)updateDataTable:(uint64_t)oldColCount{
    //容器尺寸
    CGSize size = _dataScroller.contentSize;
    size.width = self.dateArr.count*CELL_WIDTH_SMALL;
    CGFloat dataScrollerWidth = _dataScroller.frame.size.width;
    if (size.width > dataScrollerWidth) {
        _dataScroller.contentOffset = CGPointMake(size.width - dataScrollerWidth, 0);
    }
    _dataScroller.contentSize = size;
    //数据tableview尺寸
    size = _dataTable.frame.size;
    size.width = _dataScroller.contentSize.width + 1;
    CGRect datatable_frame = _dataTable.frame;
    datatable_frame.size = size;
    _dataTable.frame = datatable_frame;
    //数据头
    //先清除
    for (uint64_t i=0; i<oldColCount; i++) {
        UIView *grid = [_dataScroller viewWithTag:(NSInteger)(GRID_TAG_BASE + i + 1)];
        [grid removeFromSuperview];
    }
    //再创建
    [self createDataHead:_dataScroller];
}

#pragma mark UI渲染辅助函数
- (void)textFitSize:(NSString*)text forGrid:(UIView *)grid{
    UILabel *label = [grid viewWithTag:INNERLABEL_TAG];
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    [attrs setObject:[UIFont systemFontOfSize:13] forKey:NSFontAttributeName];
    CGSize size = [text boundingRectWithSize:CGSizeMake(MAXFLOAT, label.height)
                                     options:NSStringDrawingUsesLineFragmentOrigin
                                  attributes:attrs context:nil].size;
    if (size.width>label.width && size.width<label.width*1.5) {
        label.font = [UIFont systemFontOfSize:12];
    }
    else if (size.width>=label.width*1.5){
        label.font = [UIFont systemFontOfSize:10];
    }
    else {
        label.font = [UIFont systemFontOfSize:13];
    }
    
    label.text = text;
}
/*
- (void)updateViewConstraints{
    [_dataScroller mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view).with.offset(100);
    }];
    [_check_item_navi mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_colorIndicatorBlockL.mas_bottom);
    }];
    [_leftColList mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_check_item_navi.mas_bottom);
    }];
    
    [super updateViewConstraints];
}
 */

#pragma mark TableView 代理
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return CELL_HEIGHT_BIG;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.headColArr.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSInteger index = ROWINDEX(indexPath);
    NSString *identifier = [NSString stringWithFormat:@"cell%ld", (long)index];
    
    if (tableView==_leftColList) {
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (!cell) {
            cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
            GridBorder border = GridBorderLeft | GridBorderTop | GridBorderRight;
            if (indexPath.row == (self.headColArr.count - 1)) {
                border |= GridBorderBottom;
            }
            UIView *grid = [UIView createGrid:border
                            backgroundColor:COLOR(255, 255, 255)
                                 titleColor:TEXT_COLOR_DARK
                                  titleSize:13
                                     origin:CGPointMake(0, 0)
                                       size:CGSizeMake(CELL_WIDTH_BIG, CELL_HEIGHT_BIG)];
            grid.tag = index;
            [cell.contentView addSubview:grid];
        }
        NSDictionary *data = self.headColArr[indexPath.row];
        NSString *title = [data objectForKey:@"title"];
        NSString *ref = [data objectForKey:@"ref"];
        NSString *unit = [data valueForKey:@"unit"];
        NSString *str;
        if (!title) {
            str = @"/";
        }
        else {
            NSString *ruc = @"";//参考值和单位的组合
            if (ref && [ref isNotEmpty]) {
                if (unit) {
                    ruc = [NSString stringWithFormat:@"(%@%@)", ref, unit];
                }
                else
                    ruc = [NSString stringWithFormat:@"(%@)", ref];
            }
            str = [NSString stringWithFormat:@"%@%@", title, ruc];
        }
        UIView *grid = [cell.contentView viewWithTag:index];
        GridBorder border = GridBorderLeft | GridBorderTop | GridBorderRight;
        if (indexPath.row==_headColArr.count-1) {
            border |= GridBorderBottom;
        }
        [UIView refreshBorder:border forGrid:grid];
        [self textFitSize:str forGrid:grid];
        
        return cell;
    }
    else {
        DataGridCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
        if (!cell) {
            cell = [[DataGridCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        }
        NSMutableArray *valArr = [NSMutableArray array];
        NSDictionary *dataDic = self.indicatorDataArr[indexPath.row];
        DataRef *ref;
        if (indexPath.row<self.refArr.count) {
            ref = self.refArr[indexPath.row];
        }
        for (int j=0; j<self.dateArr.count; j++) {
            NSString *dateStr = self.dateArr[j];
            NSString *val = [dataDic objectForKey:dateStr];
            if ([val isEqualToString:@"/"] || ![val isNotEmpty]) {
                [valArr addObject:[NSDictionary dictionaryWithObjectsAndKeys:@"/", @"val", @NO, @"flag", nil]];
            }
            else {
                [valArr addObject:[NSDictionary dictionaryWithObjectsAndKeys:val, @"val", @YES, @"flag", ref, @"ref", nil]];
            }
        }
        cell.isBottom = indexPath.row==(_headColArr.count-1);
        [cell refreshData:valArr];
        return cell;
    }
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    if (scrollView==_leftColList) {
        [_dataTable setContentOffset:CGPointMake(_dataTable.contentOffset.x, _leftColList.contentOffset.y)];
    }
    if (scrollView==_dataTable) {
        [_leftColList setContentOffset:CGPointMake(_leftColList.contentOffset.x, _dataTable.contentOffset.y)];
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (tableView==_leftColList) {
        SIChartViewController *v = [SIChartViewController new];
        v.rawData = [self tidyDataForChart:indexPath];
        [self.navigationController pushViewController:v animated:YES];
    }
}

#pragma mark 数据装配
- (void)getData{
    //拿数据
    [[YZENetwork sharedInstace]getRequestWithUrl:[BASE stringByAppendingString:URL_GetSpecialIndicatorData]
                                      parameters:nil
                                        delegate:self
                                      requestTag:1
                                    successBlock:^(id responseObject)
     {
         //清旧数据
         _lastColCount = [NSNumber numberWithUnsignedInteger:_dateArr.count];
         _lastRowCount = [NSNumber numberWithUnsignedInteger:_headColArr.count];
         [_headColArr removeAllObjects];
         [_dateArr removeAllObjects];
         [_indicatorDataArr removeAllObjects];
         //整理返回的数据
         NSDictionary *data = (NSDictionary*)responseObject;
         self.reqData = [data copy];
         //合并日期数据
         NSArray *indicatorNameArr = [data allKeys];
         NSMutableDictionary *tmpDateDic = [NSMutableDictionary dictionary];
         for (NSString *indicatorName in indicatorNameArr.objectEnumerator) {
             NSDictionary *tmpIndicatorDataDic = data[indicatorName];
             NSArray *tmpDateArr = [tmpIndicatorDataDic allKeys];
             for (NSString *dateStr in tmpDateArr.objectEnumerator) {
                 tmpDateDic[dateStr] = @1;
             }
         }
         NSArray *allDateArr = [tmpDateDic allKeys];
         allDateArr = [allDateArr sortedArrayUsingComparator:^NSComparisonResult(id  _Nonnull obj1, id  _Nonnull obj2) { //日期由远及近排序
             NSString *dateStrL = obj1;
             NSString *dateStrR = obj2;
             NSDate *dateL = [TimeTools getDateWithString:[dateStrL stringByAppendingString:@" 08:00"]];
             NSTimeInterval iL = [dateL timeIntervalSince1970];
             NSDate *dateR = [TimeTools getDateWithString:[dateStrR stringByAppendingString:@" 08:00"]];
             NSTimeInterval iR = [dateR timeIntervalSince1970];
             return iL>iR;
         }];
         self.dateArr = [allDateArr mutableCopy];
         //整理结果值
         if (![DataUtils fileIfExists:SUBPROINDEX]) {
             [ZhuanXiangZhiBiaoViewController requestIndicatorData:^(NSArray *i, NSDictionary *subi) {
                 _allIndicatorArr = [i mutableCopy];
                 _subIndicatorDic = [subi mutableCopy];
                 
                 _subIndicatorChoosens = [[NSArray alloc]initWithContentsOfFile:[[DataUtils getDocumentsPath] stringByAppendingPathComponent:CHOOSEN_PROINDEX]];
                 [self tidyData:data choosenIndicator:_subIndicatorChoosens];
                 [self updateDataTable:[_lastColCount unsignedLongLongValue]];
                 [self.leftColList reloadData];
                 [self.dataTable reloadData];
             }];
         }
         else {
             _allIndicatorArr = [[NSMutableArray alloc]initWithContentsOfFile:[[DataUtils getDocumentsPath] stringByAppendingPathComponent:PROINDEXARR]];
             _subIndicatorDic = [[NSMutableDictionary alloc]initWithContentsOfFile:[[DataUtils getDocumentsPath] stringByAppendingPathComponent:SUBPROINDEX]];
             
             _subIndicatorChoosens = [[NSArray alloc]initWithContentsOfFile:[[DataUtils getDocumentsPath] stringByAppendingPathComponent:CHOOSEN_PROINDEX]];
             [self tidyData:data choosenIndicator:_subIndicatorChoosens];
             [self updateDataTable:[_lastColCount unsignedLongLongValue]];
             [self.leftColList reloadData];
             [self.dataTable reloadData];
         }
         
     }];
}
//整理数据成可被UI渲染的结构
-(void)tidyData:(NSDictionary*)data choosenIndicator:(NSArray*)choosen{
    [self.refArr removeAllObjects];
    NSArray *tmpChoosenArr = [choosen copy];
    for (NSString *indicatorNameChoosen in tmpChoosenArr.objectEnumerator) {
        for (NSString *indicatorNameInAll in _allIndicatorArr.objectEnumerator) {
            NSArray *tmpSubIndicatorArr = [RPSpecialIndicatorBean mj_objectArrayWithKeyValuesArrayAdd:_subIndicatorDic[indicatorNameInAll]];
            for (RPSpecialIndicatorBean *subIndicator in tmpSubIndicatorArr.objectEnumerator) {
                if ([subIndicator.translateProperty isEqualToString:indicatorNameChoosen]) { //比较中文名称相等，将两个字典表的数据一一对应
                    //中文名称及参考值
                    NSDictionary *headColElement = [NSDictionary dictionaryWithObjectsAndKeys:
                                                    subIndicator.translateProperty, @"title",
                                                    subIndicator.referenceValue?subIndicator.referenceValue:@"", @"ref",
                                                    subIndicator.propertyName, @"name",
                                                    subIndicator.unit, @"unit",
                                                    nil];
                    [self.headColArr addObject:headColElement];
                    //参考值
                    DataRef *ref = [DataRef new];
                    if (subIndicator.referenceValue) {
                        if ([subIndicator.referenceValue containsString:@"≤"]) {
                            NSMutableArray *limitValArr = [[subIndicator.referenceValue componentsSeparatedByString:@"≤"] mutableCopy];
                            NSEnumerator *en = [limitValArr reverseObjectEnumerator];
                            NSString *val;
                            while (val = [en nextObject]) {
                                if (![val isNotEmpty]) {
                                    [limitValArr removeObject:val];
                                }
                            }
                            
                            NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
                            [numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
                            if (limitValArr.count==1) {
                                ref.max = [numberFormatter numberFromString:limitValArr[0]];
                            }
                        }
                        else if ([subIndicator.referenceValue containsString:@"-"]){
                            NSMutableArray *limitValArr = [[subIndicator.referenceValue componentsSeparatedByString:@"-"] mutableCopy];
                            NSEnumerator *en = [limitValArr reverseObjectEnumerator];
                            NSString *val;
                            while (val = [en nextObject]) {
                                if (![val isNotEmpty]) {
                                    [limitValArr removeObject:val];
                                }
                            }
                            
                            NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init];
                            [numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
                            if (limitValArr.count==1) {
                                ref.min = [numberFormatter numberFromString:limitValArr[0]];
                            }
                            if (limitValArr.count==2) {
                                ref.min = [numberFormatter numberFromString:limitValArr[0]];
                                ref.max = [numberFormatter numberFromString:limitValArr[1]];
                            }
                        }
                    }
                    [self.refArr addObject:ref];
                    //数据
                    if (data[subIndicator.propertyName]) {
                        [self.indicatorDataArr addObject:data[subIndicator.propertyName]];
                    }
                    else {
                        [self.indicatorDataArr addObject:[NSDictionary dictionary]];
                    }
                }
            }
        }
    }
}

//整理数据供折线图使用
- (NSDictionary*)tidyDataForChart:(NSIndexPath*)indexpath{
    NSMutableDictionary *rawDic = [NSMutableDictionary dictionary];
    rawDic[@"namezh"] = _headColArr[indexpath.row][@"title"];
    NSDictionary *pnListDic = [[NSDictionary dictionary]initWithContentsOfFile:[[DataUtils getDocumentsPath] stringByAppendingPathComponent:SUBPROINDEXDIC]];
    NSDictionary *pn = pnListDic[_headColArr[indexpath.row][@"name"]];
    if (pn) {
        rawDic[@"desc"] = pn[@"desc1"];
    }
    NSMutableArray *data = [NSMutableArray array];
    NSDictionary *dateDic = self.indicatorDataArr[indexpath.row];
    NSArray *dateArr = [dateDic allKeys];
    for (NSString *dateStr in dateArr.objectEnumerator) {
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        NSDate *date = [TimeTools getDateWithString:[dateStr stringByAppendingString:@" 08:00"]];
        NSTimeInterval xval = [date timeIntervalSince1970];
        dic[@"xValue"] = [NSNumber numberWithDouble:xval];
        dic[@"y1Value"] = dateDic[dateStr];
        [data addObject:dic];
    }
    rawDic[@"data"] = data;
    rawDic[@"xlimit"] = self.refArr[indexpath.row];
    
    return rawDic;
}

#pragma mark 代理
//ZhuanXiangZhiBiaoViewControllerDelegate
- (void)backChoosenIndicators:(NSArray *)choosens{
    self.subIndicatorChoosens = [choosens copy];
    //清旧数据
    _lastRowCount = [NSNumber numberWithUnsignedInteger:_headColArr.count];
    [_indicatorDataArr removeAllObjects];
    [_headColArr removeAllObjects];
    if (!self.reqData) {
        [self getData];
    }
    else {
        _allIndicatorArr = [[NSMutableArray alloc]initWithContentsOfFile:[[DataUtils getDocumentsPath] stringByAppendingPathComponent:PROINDEXARR]];
        _subIndicatorDic = [[NSMutableDictionary alloc]initWithContentsOfFile:[[DataUtils getDocumentsPath] stringByAppendingPathComponent:SUBPROINDEX]];
        [self tidyData:self.reqData choosenIndicator:_subIndicatorChoosens];
        [self updateDataTable:[_lastColCount unsignedLongLongValue]];
        [self.leftColList reloadData];
        [self.dataTable reloadData];
    }
}

#pragma mark - UI辅助逻辑
- (void)rotate2Portrait{
    __weak AppDelegate *app = (AppDelegate*)[[UIApplication sharedApplication] delegate];
    app.allowRotation = YES;
    [app rotate2Portrait];
}

#pragma mark 属性配置
- (NSMutableArray *)dateArr{
    if (!_dateArr) {
        _dateArr = [NSMutableArray array];
        //测试数据
        [_dateArr addObjectsFromArray:@[@"/",@"/",@"/",@"/",@"/"]];
    }
    return _dateArr;
}
- (NSMutableArray *)headColArr{
    if (!_headColArr) {
        _headColArr = [NSMutableArray array];
        //测试数据
        [_headColArr addObjectsFromArray:@[@{}]];
    }
    return _headColArr;
}
- (NSMutableArray *)refArr{
    if (!_refArr) {
        _refArr = [NSMutableArray array];
    }
    return _refArr;
}
- (NSMutableArray *)indicatorDataArr{
    if (!_indicatorDataArr) {
        _indicatorDataArr = [NSMutableArray array];
        //测试数据
        [_indicatorDataArr addObjectsFromArray:@[@{@"/":@"/"}]];
    }
    return _indicatorDataArr;
}

@end





















